package org.example.delaytimetask;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

/**
 * @author chaigq
 * @version 1.0
 * @date 2021/8/31 10:15 上午
 */
public class delayTimeTask implements Job {

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {

        System.out.println("扫描数据库！");
    }

    public static void main(String[] args) throws Exception {
        // 创建定时任务
        JobDetail jobDetail = JobBuilder.newJob(delayTimeTask.class).withIdentity("delayTimeTask","group1").build();
        // 创建触发器 每3秒钟执行一次
        Trigger trigger = TriggerBuilder.newTrigger().withIdentity("TriggerJob", "groupTriggerJob").withSchedule(
                SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(3).repeatForever()
        ).build();
        // 创建调度
        Scheduler scheduler = new StdSchedulerFactory().getScheduler();
        // 将任务及触发器放入调度中
        scheduler.scheduleJob(jobDetail, trigger);
        scheduler.start();
    }
}
